using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]
public class DataController : MonoBehaviour
{
	public static DataController instance;

	public List<GameLevel> DataLevel;

	public List<GameStep> DataStep;

	public List<NpcData> DataNPC;

	public List<Attribute> DataAttribute;

	public List<LevelStar> DataLevelstar;

	public List<PosRot> AIStartPos;

	public List<NPC_ID_num> DataBuild_AI;

	public List<NPC_ID_num> DataBuild_Fri;

	public List<NPC_ID_num> DataBuild_AI_sea;

	public List<NPC_ID_num> DataBuild_Fri_sea;

	public List<NPC_ID_num> sea_ship_AI;

	public List<NPC_ID_num> sea_ship_Fri;

	public List<TDMData> tdmdata;

	public List<DTBData> dtbdata;

	public List<FFAData> ffadata;

	public List<SurData> surdata;

	public List<PieceData> piecedata;

	public float[] resultratio = new float[5]
	{
		1.3f,
		1f,
		0.8f,
		0.6f,
		0.5f
	};

	private string debuglog;

	private void Awake()
	{
		if (instance == null)
		{
			instance = this;
		}
	}

	public void list_join()
	{
		join_step_npc();
	}

	public void join_challenge_att()
	{
		join_dtb_att();
		join_ffa_att();
		join_sur_att();
		join_tdm_att();
	}

	public void join_tdm_att()
	{
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < DataAttribute.Count; j++)
			{
				if (tdmdata[i].planeatt != -1)
				{
					if (tdmdata[i].planeatt == DataAttribute[j].ID)
					{
						tdmdata[i].planeatt = j;
						break;
					}
					if (j == DataAttribute.Count - 1)
					{
						UnityEngine.Debug.Log("tdm " + i + "  not found att!");
						UnityEngine.Debug.Log("can not find id:tdm.planeatt - att");
					}
				}
			}
		}
	}

	public void join_sur_att()
	{
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < surdata[i].enemyatt.Count; j++)
			{
				for (int k = 0; k < DataAttribute.Count; k++)
				{
					if (surdata[i].enemyatt[j] != -1)
					{
						if (surdata[i].enemyatt[j] == DataAttribute[k].ID)
						{
							surdata[i].enemyatt[j] = k;
							break;
						}
						if (k == DataAttribute.Count - 1)
						{
							UnityEngine.Debug.Log("sur " + i + ": wave:" + j + "  not found att!");
							UnityEngine.Debug.Log("can not find id:sur.enemyatt - att");
						}
					}
				}
			}
		}
	}

	public void join_ffa_att()
	{
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < DataAttribute.Count; j++)
			{
				if (ffadata[i].planeatt != -1)
				{
					if (ffadata[i].planeatt == DataAttribute[j].ID)
					{
						ffadata[i].planeatt = j;
						break;
					}
					if (j == DataAttribute.Count - 1)
					{
						UnityEngine.Debug.Log("ffa " + i + "  not found att!");
						UnityEngine.Debug.Log("can not find id:ffa.planeatt - att");
					}
				}
			}
		}
	}

	public void join_dtb_att()
	{
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < DataAttribute.Count; j++)
			{
				if (dtbdata[i].planeatt != -1)
				{
					if (dtbdata[i].planeatt == DataAttribute[j].ID)
					{
						dtbdata[i].planeatt = j;
						break;
					}
					if (j == DataAttribute.Count - 1)
					{
						UnityEngine.Debug.Log("dtb " + i + ": plane not found att!");
						UnityEngine.Debug.Log("can not find id:dtb.planeatt-attribute");
					}
				}
			}
			for (int k = 0; k < dtbdata[i].buildatt.Count; k++)
			{
				for (int l = 0; l < DataAttribute.Count; l++)
				{
					if (dtbdata[i].buildatt[k] != -1)
					{
						if (dtbdata[i].buildatt[k] == DataAttribute[l].ID)
						{
							dtbdata[i].buildatt[k] = l;
							break;
						}
						if (l == DataAttribute.Count - 1)
						{
							UnityEngine.Debug.Log("dtb " + i + ": build:" + k + "  not found att!");
							UnityEngine.Debug.Log("can not find id: dtb.build - att");
						}
					}
				}
			}
			for (int m = 0; m < dtbdata[i].shipatt.Count; m++)
			{
				for (int n = 0; n < DataAttribute.Count; n++)
				{
					if (dtbdata[i].shipatt[m] != -1)
					{
						if (dtbdata[i].shipatt[m] == DataAttribute[n].ID)
						{
							dtbdata[i].shipatt[m] = n;
							break;
						}
						if (n == DataAttribute.Count - 1)
						{
							UnityEngine.Debug.Log("dtb " + i + ": build:" + m + "  not found att!");
							UnityEngine.Debug.Log("can not find id: dtb.ship - att");
						}
					}
				}
			}
		}
	}

	public void join_level_step()
	{
		for (int i = 0; i < DataLevel.Count; i++)
		{
			for (int j = 0; j < DataLevel[i].gamestepid.Count; j++)
			{
				if (DataLevel[i].gamestepid[j] == -1)
				{
					continue;
				}
				for (int k = 0; k < DataStep.Count; k++)
				{
					if (DataLevel[i].gamestepid[j] == DataStep[k].ID)
					{
						DataLevel[i].gamestepid[j] = k;
						break;
					}
					if (k == DataStep.Count - 1)
					{
						UnityEngine.Debug.Log(" can not find the ID:level--step");
					}
				}
			}
		}
	}

	public void join_step_npc()
	{
		debuglog = null;
		for (int i = 0; i < DataStep.Count; i++)
		{
			for (int j = 0; j < DataStep[i].enemy_id_num.Count; j++)
			{
				for (int k = 0; k < DataNPC.Count; k++)
				{
					if (DataStep[i].enemy_id_num[j].ID != -1)
					{
						if (DataStep[i].enemy_id_num[j].ID == DataNPC[k].ID)
						{
							DataStep[i].enemy_id_num[j].ID = k;
							break;
						}
						if (k == DataNPC.Count - 1)
						{
							string text = debuglog;
							debuglog = text + DataStep[i].ID + ": enemy  " + (j + 1) + "\n";
							UnityEngine.Debug.Log(DataStep[i].ID + ": enemy  " + (j + 1));
							UnityEngine.Debug.Log(" can not find id: step_enemy_id--npc");
						}
					}
				}
			}
			for (int l = 0; l < DataStep[i].fri_id_num.Count; l++)
			{
				for (int m = 0; m < DataNPC.Count; m++)
				{
					if (DataStep[i].fri_id_num[l].ID != -1)
					{
						if (DataStep[i].fri_id_num[l].ID == DataNPC[m].ID)
						{
							DataStep[i].fri_id_num[l].ID = m;
							break;
						}
						if (m == DataNPC.Count - 1)
						{
							string text = debuglog;
							debuglog = text + DataStep[i].ID + ": fri  " + (l + 1) + "\n";
							UnityEngine.Debug.Log(DataStep[i].ID + ": fri  " + (l + 1));
							UnityEngine.Debug.Log(" can not find id: step_fri_id--npc");
						}
					}
				}
			}
		}
		MonoBehaviour.print(debuglog);
	}

	public void join_npc_att()
	{
		for (int i = 0; i < DataNPC.Count; i++)
		{
			for (int j = 0; j < DataAttribute.Count; j++)
			{
				if (DataNPC[i].attribute_id != -1)
				{
					if (DataNPC[i].attribute_id == DataAttribute[j].ID)
					{
						DataNPC[i].attribute_id = j;
						break;
					}
					if (j == DataAttribute.Count - 1)
					{
						UnityEngine.Debug.Log("can not find id:npc_att--attribute");
					}
				}
			}
		}
	}

	public void join_level_star()
	{
		for (int i = 0; i < DataLevel.Count; i++)
		{
			for (int j = 0; j < DataLevel[i].starid.Count; j++)
			{
				if (DataLevel[i].starid[j] == -1)
				{
					continue;
				}
				for (int k = 0; k < DataLevelstar.Count; k++)
				{
					if (DataLevel[i].starid[j] == DataLevelstar[k].ID)
					{
						DataLevel[i].starid[j] = k;
						break;
					}
					if (k == DataLevelstar.Count - 1)
					{
						UnityEngine.Debug.Log(" can not find the ID:level--star");
					}
				}
			}
		}
	}

	public PieceData Getpiece(int id)
	{
		if (id < piecedata.Count)
		{
			return piecedata[id];
		}
		MonoBehaviour.print("not found piece!");
		return null;
	}

	private void OnDestroy()
	{
		if (instance != null)
		{
			instance = null;
		}
	}
}
